package com.demo;

/**
 * @Description: 几何类
 * @Author: JKchen
 * @Date: 2022/10/30 15:48
 */
public abstract class Shape {
    String name;
    //有参构造
    public Shape(String name){
     this.name=name;
    }
    public abstract double getArea();
    public abstract double getPerimeter();

    public static void main(String[] args) {
        double d=0.0;
        Shape[] shapes = new Shape[5];
        for(int i=0;i<shapes.length;i++){
            d=Math.random();
            if(d>0.5){
                shapes[i]=new circle(1);

            }else{
                shapes[i]=new Rectangle(1,2);
            }

        }
        double sum=0;
        for (Shape i:shapes) {
            System.out.println(i.getArea());
            sum+=i.getArea();
        }
        System.out.println((int)sum);
    }
}
